<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="发帖人">
              <a-input
                placeholder="请输入发帖人"
                v-model="queryParam.nickname"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="帖子类型">
              <a-select
                v-model="queryParam.postType"
                placeholder="请选择帖子类型"
              >
                <a-select-option value="">全部</a-select-option>
                <a-select-option value="健康">健康</a-select-option>
                <a-select-option value="姻缘">姻缘</a-select-option>
                <a-select-option value="事业">事业</a-select-option>
                <a-select-option value="财富">财富</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="关键词">
              <a-date-picker  valueFormat='YYYY-MM-DD' v-model="queryParam.commentTime"    style="width: 100%"/>
            </a-form-item>
          </a-col> -->
          <template v-if="toggleSearchStatus">
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="发布时间">
              <a-input placeholder="请输入发布时间" v-model="queryParam.releaseTime"></a-input>
              <a-date-picker  valueFormat='YYYY-MM-DD' v-model="queryParam.commentTime"/>
            </a-form-item>
          </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户id">
              <a-input placeholder="请输入用户id" v-model="queryParam.userId"></a-input>
            </a-form-item>
          </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户头像">
              <a-input placeholder="请输入用户头像" v-model="queryParam.headPortrait"></a-input>
            </a-form-item>
          </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span
              style="float: left;overflow: hidden;"
              class="table-page-search-submitButtons"
            >
              <a-button type="primary" @click="searchQuery" icon="search"
                >查询</a-button
              >
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
                >重置</a-button
              >
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? "收起" : "展开" }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus"
        >发布帖子</a-button
      >
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('帖子管理2')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-wrap"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        @change="handleTableChange"
      >
        <span slot="postContent" slot-scope="text, record">
          {{ text.slice(0, 100) }}
          <a v-if="text.length > 200" @click="Imgdetail(record.postContent, 1)"
            >......</a
          >
        </span>
        <span slot="headPortrait" slot-scope="text">
          <a-avatar :src="text" />
        </span>
        <span slot="numberOfComments" slot-scope="text, record">
          {{ text }}&nbsp;&nbsp;&nbsp;<a @click="isModal(record.id)"
            >评论管理</a
          >
        </span>
        <span slot="postPicture" slot-scope="text, record">
          <!-- <img :src="item.pricturePath" v-for="(item,index) in text" @click="Open(item.pricturePath)" :key=index alt="" style="width: 50px;height: 50px;margin-left: 10px;"/> -->
          <img
            :src="record.postPicture[0].pricturePath"
            style="width: 50px;height: 50px;"
            v-if="record.postPicture != null"
          />
          <span v-else>暂无图片</span>
          <a-divider type="vertical" v-if="record.postPicture != null" />
          <a
            v-if="record.postPicture != null"
            @click="Imgdetail(record.postPicture, 2)"
            >......</a
          >
        </span>
        <span slot="isTop" slot-scope="text">
          {{ text == 0 ? "否" : text == 1 ? "是" : "" }}
        </span>
        <span slot="action" slot-scope="text, record, index">
          <a @click="handleEdit(record, '4')">查看</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="zhiding(record, index)">{{
            record.isTop == 0 ? "置顶" : "取消置顶"
          }}</a>
          <a-divider type="vertical" />
          <a-popconfirm
              title="确定屏蔽吗?"
              @confirm="() => pingbi(record.id, index)"
            >
              <a>{{
                record.postState == 0
                  ? "屏蔽"
                  : record.postState == 2
                  ? "发布"
                  : ""
              }}</a>
            </a-popconfirm>
            <a-divider type="vertical" />
            <a-popconfirm
              title="确定删除吗?"
              @confirm="() => handleDelete(record.id)"
            >
              <a>删除</a>
            </a-popconfirm>
          <!-- <a-dropdown class="aa">
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete(record.id)"
                >
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm
                  title="确定屏蔽吗?"
                  @confirm="() => pingbi(record.id, index)"
                >
                  <a>{{
                    record.postState == 0
                      ? "屏蔽"
                      : record.postState == 2
                      ? "发布"
                      : ""
                  }}</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <postInformation2-modal
      ref="modalForm"
      @ok="modalFormOk"
    ></postInformation2-modal>
    <plsysModel
      ref="plsysModal"
      :pldata="pldata"
      @callback="callback"
    ></plsysModel>
    <Imgdetail
      :imgdata="imgdata"
      :imgtype="imgtype"
      :content="content"
    ></Imgdetail>
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import PostInformation2Modal from "./modules/PostInformation2Modal";
import plsysModel from "./modules/plsysModel";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { httpAction, getAction } from "@/api/manage";
import { imgpath } from "@/api/tsapi";
import Imgdetail from "./modules/Imgdetail";
export default {
  name: "PostInformation2List",
  mixins: [JeecgListMixin],
  components: {
    PostInformation2Modal,
    plsysModel,
    Imgdetail,
  },
  data() {
    return {
      description: "帖子管理2管理页面",
      // 表头
      columns: [
        {
          title: "发帖人",
          align: "center",
          dataIndex: "nickname",
        },
        {
          title: "帖子内容",
          align: "center",
          dataIndex: "postContent",
          width: "400px",
          scopedSlots: { customRender: "postContent" },
        },
        {
          title: "图片",
          align: "center",
          dataIndex: "postPicture",
          scopedSlots: { customRender: "postPicture" },
        },

        {
          title: "置顶",
          align: "center",
          dataIndex: "isTop",
          scopedSlots: { customRender: "isTop" },
        },
        {
          title: "点赞",
          align: "center",
          dataIndex: "numberLikes",
        },
        {
          title: "发布时间",
          align: "center",
          dataIndex: "createTime",
        },
        {
          title: "评论",
          align: "center",
          dataIndex: "numberOfComments",
          scopedSlots: { customRender: "numberOfComments" },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: "action" },
        },
      ],
      url: {
        list: "/post/postInformation/PagePostListPc",
        delete: "/post/postInformation/delete",
        deleteBatch: "/postInformation/postInformation/deleteBatch",
        exportXlsUrl: "postInformation/postInformation/exportXls",
        importExcelUrl: "postInformation/postInformation/importExcel",
        zding: "/post/postInformation/edit",
        syncUser: "/postComment/postComment/list",
      },
      pldata: [],
      plid: "",
      imgdata: [], //图片详情
      imgtype: "",
      content: "",
      pageNo: 1,
      pageSize: 10,
    };
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    Open(patn) {
      window.open(patn);
    },
    //置顶
    zhiding(record, index) {
      let httpurl = this.url.zding;
      let method = "post";
      let params = {
        id: record.id,
        isTop: this.dataSource[index].isTop == 0 ? 1 : 0,
      };
      httpAction(httpurl, params, method).then((res) => {
        this.loadData();
      });
    },
    //屏蔽
    pingbi(id, index) {
      let httpurl = this.url.zding;
      let method = "post";
      let params = {
        id: id,
        postState: this.dataSource[index].postState == 0 ? 2 : 0,
      };
      httpAction(httpurl, params, method).then((res) => {
        this.loadData();
      });
    },
    isModal(id, pa) {
      this.plid = id;
      let url = this.url.syncUser;
      let params = {
        postInformationId: id,
        commentTime: pa == undefined ? "" : pa.time,
        pageNo:this.pageNo,
        pageSize:this.pageSize
      };
      getAction(url, params).then((res) => {
        this.pldata = res.result;
        this.$children[0].$children[4].ipaginations.total = res.result.total
      });
      this.$refs.plsysModal.visible = true;
    },
    callback(params) {
      this.isModal(this.plid, params);
    },
    ImgPath: function(params) {
      return imgpath(params);
    },
    Imgdetail(data, type) {
      console.log(data, "data");
      this.$children[0].$children[5].visible = true;
      this.imgtype = type;
      if (type == 1) {
        this.content = data;
      } else {
        this.imgdata = data;
      }
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
